package org.openfdtd.core3d;

import java.util.Locale;
import java.util.ArrayList;
import javax.vecmath.Point3d;

/**
 *
 * @author Dorian C. Langbeck
 */
public class Vertex extends Point3d {
    private ArrayList<Edge> parents = new ArrayList<Edge>();

    public Vertex(double[] p) {
        setCoordinate(p);
    }

    public Vertex(double x, double y, double z) {
        super(x, y, z);
    }

    public double[] getCoordinate() {
        return new double[] {x, y, z};
    }

    public void setCoordinate(double[] p) {
        x = p[0];
        y = p[1];
        z = p[2];
    }

    public boolean equals(Vertex v) {
        return equals(v);
    }

    public void childOf(Edge e) {
        parents.add(e);
    }

    public Edge[] getParents() {
        return (Edge[]) parents.toArray();
    }

    public boolean removeParent(Edge e) {
        return parents.remove(e);
    }

    public boolean isChildOf(Edge e) {
        return parents.contains(e);
    }

    @Override
    public String toString() {
        return String.format(Locale.US, "%s[x=%f,y=%f,z=%f]", getClass().getName(), getX(), getY(), getZ());
    }
}
